/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 徐海涛
 * Date: 2022-02-15
 * Time: 19:32
 */
class MyArray<T> {//T当做是一个占位符
    public Object[] objects = new Object[10];//不能实例化 泛形类型的数组

    public void set(int pos, int val) {
        objects[pos] = val;
    }

    public Object get(int pos) {
        return objects[pos];
    }
}

/**
 * 写一个泛形类，求数组当中的最大值
 */
//不在主函数里面new一个新对象我们该如何去写 此时我们使用泛形的方法
    //加static
class Alg3 {
    public static <T extends  Comparable<T>> T findMax(T[] array) {
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i])<0) {
                max = array[i];
            }
        }
        return max;
    }
}
class Alg2<T extends Comparable<T>> {
    //T extends x 泛形的上界
    public T findMax2(T[] array) {
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i])<0) {
                max = array[i];
            }
        }
        return max;
    }
}
class Alg1<T extends Comparable<T>> {
    public T findMax(T[] array) {
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i])<0)  {
                max = array[i];
            }
        }
        return max;
    }

}
public class TestDemo {
    public static void main(String[] args) {
        Integer[] array = {1,12,3,4};
        System.out.println(Alg3.findMax(array));
    }
    public static void main1(String[] args) {
        MyArray myArray = new MyArray();

        myArray.set(1,10);
        String str = (String) myArray.get(0);
    }

}

